package com.kfm.mvn.dao;

import com.kfm.mvn.model.File;
import com.kfm.mvn.util.DBHelper;

import java.sql.SQLException;
import java.util.List;

/**
 * 文件数据访问类
 */
public class FileDao {

    private DBHelper dbHelper = new DBHelper();

    public List<File> selectAll() throws SQLException {
        String sql = "select * from file";
        return dbHelper.selectList(sql, File.class);
    }

    public int save(File file){
        String sql = "insert into file(name, path, size, type, create_user) values(?,?,?,?,?)";
        try {
            return dbHelper.update(sql, file.getName(), file.getPath(), file.getSize(), file.getType(), file.getCreateUser());
        } catch (SQLException e) {
            e.printStackTrace();
            return 0;
        }
    }
}
